<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  
<title>在线试题测试</title>
	<meta http-equiv="content-type" content="txt/html; charset=utf-8" />	
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
	  <script src="js/jquery-3.3.1.js"></script>
	<style>
		body { background-color: #fff; width: 100%; height: 100%;}
	</style>
</head>

<script type="text/javascript">

	//aryAns[]是从后端返回的数组,当点击交卷的时候,向后端请求正确答案的数组,赋值给aryAns[]即可;
	var aryAns = new Array();   //建立储存正确答案的数组

	$(function () {
		load();
	});

	function load() {
		$.get("user/onlineQuestions",{},function (data) {
			var lis = '<center>\n' +
					'\t\t<p>&nbsp;</p>\n' +
					'\t\t<p><font size="6" color="green"><b>在线检测</b></font>\n' +
					'\t\t</p>\n' +
					'\t\t<h1>测试已开始请开始作答<span id="mytime">00:00:00</span></h1>\n' +
					'\n' +
					'\t</center>\n' +
					'\t<br>\n' +
					'  \t<hr>';

			for (var i = 0; i < 5; i++) {
				let qs = data[i];
				let index = i+1;
				let ops = qs.options;
				aryAns.push(qs.answer);
				var li = '';
				if(ops.option_d == null){
					li = '<p><strong>'+index+'.'+qs.question+'</strong></p>\n' +
							'  \t\t<p>\n' +
							'  \t\t\t<input type="radio" name="Q'+index+'" value="1">'+ops.option_a+'   \n' +
							'  \t\t\t<input type="radio" name="Q'+index+'" value="2">'+ops.option_b+'\n' +
							'  \t\t\t<input type="radio" name="Q'+index+'" value="3">'+ops.option_c+'\n' +
							'\n' +
							'  \t\t</p>';
				}else{
					 li = '<p><strong>'+index+'.'+qs.question+'</strong></p>\n' +
							'  \t\t<p>\n' +
							'  \t\t\t<input type="radio" name="Q'+index+'" value="1">'+ops.option_a+'   \n' +
							'  \t\t\t<input type="radio" name="Q'+index+'" value="2">'+ops.option_b+'\n' +
							'  \t\t\t<input type="radio" name="Q'+index+'" value="3">'+ops.option_c+'\n' +
							'  \t\t  <input type="radio" name="Q'+index+'" value="4">'+ops.option_d+'\n' +
							'\n' +
							'  \t\t</p>';
				}

				lis += li;
			}

			var post = '<button onClick="javascript:main();">交卷</button>       <button onClick="javascript:window.location.reload();">重做</button>  <!--  <input type="button" onClick="javascript:window.location.reload() " value="重做"/>  -->\n' +
					'  \t\t<h3>\n' +
					'\t\t\t5道题中您一共答对了<font color="red"><span id="right_number"></span></font>题，\n' +
					'  \t\t花了<font color="red"><span id="time"></span></font>秒\n' +
					'      <br>\n' +
					'      正确的题目有:<span id="right_question" style="color:red"></span>\n' +
					'       <br>\n' +
					'      错误的题目有:<span id="error_question" style="color:red"></span>\n' +
					'  \t\t</h3>';
			lis += post;

			$("#body").html(lis);

		})
	}
 
function two_char(n) {
		return n >= 10 ? n : "0" + n;
}

function time_fun() {
	var sec=0;
	setInterval(function () {
		sec++;
		var date = new Date(0, 0)
		date.setSeconds(sec);
		var h = date.getHours(), m = date.getMinutes(), s = date.getSeconds();
		document.getElementById("mytime").innerText = two_char(h) + ":" + two_char(m) + ":" + two_char(s);
	}, 1000);
}
 
function main(){
  var questionArray = new Array("Q1","Q2","Q3","Q4","Q5");
  var resultArray = new Array();
  var rightArray = new Array();

  for (var i = 0; i < questionArray.length; i++) {
    if (Name(questionArray[i])!=5) {
      resultArray[i] = Name(questionArray[i]); 
    }else{
      alert("第"+(i+1)+"题,您未作答!!");
      return false;
    }
  }
  var right_number= 0;//计算答对的题数；
  for (var i = 0; i < questionArray.length; i++) {
    if (aryAns[i]==resultArray[i]) {
          right_number++;
          rightArray[i] = 1;
    }else{
          rightArray[i] = 0;
    }
  }
  var right_question = " ";
  var error_question = " ";
  for (var i = 0; i < rightArray.length; i++) {
      if (rightArray[i] ==1 ) {
          right_question += i+1+",";
      }else{
          error_question += i+1+",";
      }
  }

 	let score = right_number * 20;

	//提交考试数据至数据库
	$.post("user/onlineTest",{score:score},function(data){
		if(data.flag){
			alert("提交成功");
		}else{
			alert(data.errorMsg);
		}
		var time=document.getElementById("mytime").innerHTML;
		document.getElementById("right_number").innerText = right_number;
		document.getElementById("time").innerText = time;
		if (right_question!=" ") {
			document.getElementById("right_question").innerText = right_question;
		}
		if (error_question!=" ") {
			document.getElementById("error_question").innerText = error_question;
		}
	});
};
 
function Name(name)
{
  var temp = document.getElementsByName(name);
  var intHot = 9;
  for(var i=0;i<temp.length;i++)
  {
     if(temp[i].checked)
      intHot = temp[i].value;
  }
  if (intHot==9) {
      return 10;
  }
  return intHot;
};
</script>

<body id="body" onLoad="time_fun()" style="padding:0px; margin-left: 50px;">
	<center>
		<p>&nbsp;</p>
		<p><font size="6" color="green"><b>在线检测</b></font>
		</p>
		<h1>测试已开始请开始作答<span id="mytime">00:00:00</span></h1>

	</center><br>
	<hr>

  	<!--  下面表单将以post的方法，将数据传递给Text -->
  		<!-- 第一道题 -->
		单选题（共10题）<br>
	  <p><strong>1.利用该命令可以显示有关统计信息和当前TCP/IP网络连接的情况，用户或网络管理人员可以得到非常详尽的统计结果（）</strong></p>
  		<p>
  			<input type="radio" name="Q1" value="1">A．ipconfig
  			<input type="radio" name="Q1" value="2">B．netstat
  			<input type="radio" name="Q1" value="3">C．tracert
			<input type="radio" name="Q1" value="4">D．ping
			</p>
  		<p><strong>2．物理层网络故障的主要现象是() 。</strong></p>
  		<p>
  			<input type="radio" name="Q2" value="1">A．硬件故障
  			<input type="radio" name="Q2" value="2">B．线路故障
  			<input type="radio" name="Q2" value="3">C．逻辑故障
  			<input type="radio" name="Q2" value="3">D．以上都是
  		</p>
		<p><strong>3.路由器故障诊断可以使用多种工具()。</strong></p>
  		<p>
  			<input type="radio" name="Q3" value="1">A．路由器诊断命令
  			<input type="radio" name="Q3" value="2">B．网络管理工具
  			<input type="radio" name="Q3" value="3">C．以上都是
  			
  		</p>
  		<p><strong>4.以下哪一种不是路由器广域网接口()</strong></p>
  		<p>
  			<input type="radio" name="Q4" value="1">A．RJ-45   
  			<input type="radio" name="Q4" value="2">B．FDDI
  			<input type="radio" name="Q4" value="3">C．AUI端口
  		  <input type="radio" name="Q4" value="4">D．高速同步接口

  		</p>
  		<p><strong>5.以太网中，如果发现半/全双工冲突问题，下列哪一种不是采取的方法()</strong></p>
  		<p>
  			<input type="radio" name="Q5" value="1">A．两端都设置为自适应
  			<input type="radio" name="Q5" value="2">B．两端都设置为半双工
  			<input type="radio" name="Q5" value="3">C．两端都设置为半单工
  		    <input type="radio" name="Q5" value="4">D．两端都设置为全双工
  		</p>
		
		<p><strong>6.以下哪一种不是ISDN基本连接方式() </strong></p>
  		<p>
  			<input type="radio" name="Q6" value="1">A．使用外置终端适配器
  			<input type="radio" name="Q6" value="2">B．使用内置ISDN PC卡和数字电话
  			<input type="radio" name="Q6" value="3">C．使用普通PCI网卡
  			<input type="radio" name="Q6" value="4">D．兼用内外置适配器
		</p>
		
		
		
		<p><strong>7.ARP地址冲突故障是由（）造成的 </strong></p>
  		<p>
  			<input type="radio" name="Q7" value="1">A．操作 
  			<input type="radio" name="Q7" value="2">B．ARP欺骗
			<input type="radio" name="Q7" value="3">C．ARP攻击
			<input type="radio" name="Q7" value="3">D．以上都是
		</p>
		
		
				
		
		<p><strong>8.服务器软件故障排除三个方面（） </strong></p>
  		<p>
  			<input type="radio" name="Q8" value="1">A．经常对Firmware及BIOS进行更新
  			<input type="radio" name="Q8" value="2">B．是服务器软件的更新
  			<input type="radio" name="Q8" value="3">C．因人为因素造成的软件故障
  			<input type="radio" name="Q8" value="3">D．以上都是
		</p>
		
		
				
		
		<p><strong>9.常用的防火墙包括（） </strong></p>
  		<p>
  			<input type="radio" name="Q9" value="1">A．包过滤防火墙
  			<input type="radio" name="Q9" value="2">B．应用级防火墙
			<input type="radio" name="Q9" value="3">C．状态检测防火墙
			<input type="radio" name="Q9" value="3">D．以上都是
  			
		</p>
		

		<p><strong>10.无线网络中的安全缺陷主要有()</strong></p>
  		<p>
  			<input type="radio" name="Q10" value="1">A．数据传输的安全缺陷 
  			<input type="radio" name="Q10" value="2">B．身份认证WEP的安全缺陷
  			<input type="radio" name="Q10" value="3">C．服务集标识符SSID的安全缺陷 
				<input type="radio" name="Q10" value="3">C．以上都是
		</p>
		
		
      <button onClick="javascript:main();">交卷</button>       <button onClick="javascript:window.location.reload();">重做</button>  <!--  <input type="button" onClick="javascript:window.location.reload() " value="重做"/>  -->
  		<h3>
			10道题中您一共答对了<font color="red"><span id="right_number"></span></font>题，
  		花了<font color="red"><span id="time"></span></font>秒
      <br>
      正确的题目有:<span id="right_question" style="color:red"></span>
       <br>
      错误的题目有:<span id="error_question" style="color:red"></span>
  		</h3>
</body>
</html>
